package org.zkoss.zktc.unittest;

import org.junit.Assert;
import org.junit.Test;
import org.zkoss.zktc.core.junit.TestCaseBase;
import org.zkoss.zktc.core.widget.Widget;
import org.zkoss.zktc.core.widget.WidgetDriver;

public class ButtonTestCase extends TestCaseBase{

	protected String getTestCaseUrl(){
		return getTestCaseUrl("/unit/button.zul");
	}
	
	@Test
	public void testButtonClick(){
		WidgetDriver driver = getDriver();
		navigate(getTestCaseUrl());
		
		Widget wd = findWidget("$btn1");
		Assert.assertNotNull(wd);
		Assert.assertEquals("Button1", wd.getLabel());
		Assert.assertEquals("zul.wgt.Button", wd.getAttribute("className"));
		
		wd.setAttribute("label", "My Button1");
		Assert.assertEquals("My Button1", wd.getLabel());
		
		
		wd.click();
		wd = findWidget("@window .z-label");
		Assert.assertNotNull(wd);
		Assert.assertEquals("Hello Button1", wd.getValue());
		
		wd = findWidget("@window @button");
		Assert.assertNotNull(wd);
		wd.click(1,1000);
		wd = findWidget("@window .z-label",0);
		Assert.assertNull(wd);
		
		//test dbclick and right click
		wd = findWidget("$btn1");
		wd.dbclick(0,0);
		waitForTrip(1,1000);
		Assert.assertNull(findWidget("@window .z-label",0));
		wd.rclick(0,0);
		waitForTrip(1,1000);
		Assert.assertNull(findWidget("@window .z-label",0));
		
		
		wd = findWidget("$btn2");
		Assert.assertNotNull(wd);
		Assert.assertEquals("Button2", wd.getLabel());
		Assert.assertEquals("zul.wgt.Button", wd.getAttribute("className"));
		
		wd.dbclick();
		wd = findWidget("@window .z-label");
		Assert.assertNotNull(wd);
		Assert.assertEquals("Hello Button2", wd.getValue());

		wd = findWidget("@window @button");
		Assert.assertNotNull(wd);
		wd.click(1,1000);
		wd = findWidget("@window .z-label",0);
		Assert.assertNull(wd);
		
		
		
		
		wd = findWidget("$btn3");
		Assert.assertNotNull(wd);
		Assert.assertEquals("Button3", wd.getLabel());
		Assert.assertEquals("zul.wgt.Button", wd.getAttribute("className"));
		
		wd.rclick();
		wd = findWidget("@window .z-label");
		Assert.assertNotNull(wd);
		Assert.assertEquals("Hello Button3", wd.getValue());
		
		wd = findWidget("@window @button");
		Assert.assertNotNull(wd);
		wd.click(1,1000);
		wd = findWidget("@window .z-label",0);
		Assert.assertNull(wd);
		
	}
	
	
}
